Sams Teach Yourself C++ in 24 Hours, Sixth Edition (shannon powell's Library) by Rogers Cadenhead & Jesse Liberty

Sams Teach Yourself C++ in 24 Hours, Sixth Edition (shannon powell's Library) by Rogers Cadenhead & Jesse Liberty

Author:Rogers Cadenhead & Jesse Liberty
Language: eng
Format: epub
Publisher: Sams Publishing
Published: 2017-06-25T16:00:00+00:00


* * *

1: #include <iostream>

2:

3: class Tricycle

4: {

5: public:

6: Tricycle();

7: // copy constructor and destructor use default

8: int getSpeed() const { return *speed; }

9: void setSpeed(int newSpeed) { *speed = newSpeed; }

10: Tricycle operator=(const Tricycle&);

11:

12: private:

13: int *speed;

14: };

15:

16: Tricycle::Tricycle()

17: {

18: speed = new int;

19: *speed = 5;

20: }

21:

22: Tricycle Tricycle::operator=(const Tricycle& rhs)

23: {

24: if (this == &rhs)

25: return *this;

26: delete speed;

27: speed = new int;

28: *speed = rhs.getSpeed();

29: return *this;

30: }

31:

32: int main()

33: {

34: Tricycle wichita;

35: std::cout << "Wichita's speed: " << wichita.getSpeed()

36: << std::endl;

37: std::cout << "Setting Wichita's speed to 6 ..." << std::endl;

38: wichita.setSpeed(6);

39: Tricycle dallas;

40: std::cout << "Dallas' speed: " << dallas.getSpeed()

41: << std::endl;

42: std::cout << "Copying Wichita to Dallas ..." << std::endl;

43: wichita = dallas;

44: std::cout << "Dallas' speed: " << dallas.getSpeed()

45: << std::endl;

46: return 0;

47: }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.